Loading...
 

Documentation of printing via the OLE interface

Documentation of printing via the OLE interface

Table of contents:
  1. Setting headers and footers
  2. Inserting general Word texts
  3. Inserting section breaks and new headers
  4. Further output options
  5. Printing options / Preview
More links:

When printing via the OLE interface, VBA commands are increasingly used. Since the calls involved in printing are not described in the Instantview® or CyberEnterprise® documentation, this section will deal with them. In addition, the differences to the old printing method will be discussed.

Thus, the new printing does not start with the creation of a CXS document in which the blocks are inserted, but now a Word object is created directly. This is then assigned a format template with the same formats as those used in the modules and other Word objects involved in printing in the database. (see script print training)

// Create new word object
CreateTransObject(CX_COM_OBJECT) -> objectClip
"Word.Document" objectClip Call(CreateFromProgID)

strDotPath applicationClip Call(GetAddIns) Call(Add)
applicationClip
Call(Lock)
// format settings
"-1" Integer objectClip Call(PutUpdateStylesOnOpen)
strDotPath objectClip
Call(PutAttachedTemplate)

1. setting headers and footers

The next step is to set the headers and footers for the document. Since we usually use different headers on the first and subsequent pages, we must also assign this to the Word object.

// Set different page headers
(-1) objectClip Dup Call(Activate) Call(GetPageSetup) Call(PutDifferentFirstPageHeaderFooter)

Now we can set the footer, for example. The oleObj is the Word object that should be inserted as a footer. The commented out part in the first line represents the locking of the fields, which means that their contents cannot be updated. But since the footer only has the page number field, we are not allowed to execute this code here. Otherwise the field would not update and would always display '1', regardless of the page. The Call(GetContent) command selects all the content, which we copy to the clipboard using Call(Copy). Now we just have to paste the copied part.

A Word document can be divided into several (at least one) sections and via Call(GetSections) Call(GetLast) we address the last, i.e. the current part. Since we have previously set the flag 'DifferentFirstPageHeaderFooter', we must now address two different footer elements. Call(GetFooters) Call(Item) with the transfer parameter '2' addresses the first page and the parameter '1' addresses the following pages. The content from the clipboard is then pasted in both cases via Call(GetRange) Call(Paste).

oleObj Call(Activate) oleObj Call(GetContent) /*Dup Call(GetFields) "-1" Swap Call(PutLocked)*/ Call(Copy)
// get page footer for page 1 + 1...1+n
2 objectClip Dup Call(Activate) Call(GetSections) Call(GetLast) Call(GetHeaders) Call(Item) Call(GetRange) Call(Paste)
1 objectClip Dup Call(Activate) Call(GetSections) Call(GetLast) Call(GetFooters) Call(Item) Call(GetRange) Call(Paste)

The same happens when setting the headers, except that the inserted contents are not identical and in the call the Call(GetFooters) statement is replaced by Call(GetHeaders).

2. insertion of general Word texts

The insertion of further content is similarly simple. We have a Word document where we lock the fields and copy the whole content. Now we jump to the current position in our Word object to be printed (Call(GetApplication) Call(GetSelection)) and note this in the variable 'Selection'. The 'Call(Paste)' call still inserts the content from the clipboard.

DropAll
// Copy document component
tmpOleObj Du Call(Activate) Call(GetContent) Du Call(GetFields) "-1" Swap Call(PutLocked) Call(Copy)
// Jump into the document
objectClip Dup Call(Activate) Call(GetApplication) Call(GetSelection) -> selection

// paste component into document
selection Call(Paste)

3. inserting section breaks and new headers

With the commands shown so far, you could already create a form, but for example, outputting longer lists with a list heading that repeats on every page would be limited. To realize this, we need to insert a new section so that we can set new headers. First, we jump back to the current position in the document and remember it. Via the variable pageBreakType we pass the type of the section break. Call(GetSections) Call(Add) inserts the simple change with page break. In the other case '1' a running section break is created.

objectClip Call(GetApplication) Call(GetSelection) -> selection
pageBreakType
case
        0          :  selection Call(GetSections) Call(Add) Drop
                       TRUE -> beginOfNewPage
        1          :  selection Dup Call(GetRange) Swap Call(GetSections) 0 Swap Call(Add) Drop
endCase

Now we can set new headers again in the middle of the document. For example, we can output the list heading in addition to the previous header content, which is then automatically repeated on each page. But before we can do this, there is one more thing we have to consider. Since the headers are also connected to each other across sections, any changes would also change the previous headers. So we have to disconnect the connection first.

objectClip Call(GetSections) Call(GetLast) Call(GetHeaders) 1 Swap Call(Item) -> tmpHeaderItem1
0 tmpHeaderItem1 Call(PutLinkToPrevious)

4. further output options

- direct output of simple texts
"Sample Text" selection Call(PutText)

- Output of a line break
selection Call(TypeParagraph)

5. printing options / preview

Preview
The preview of Word can be generated with the command Call(PrintPreview) after we have opened the generated object. Afterwards we can manually make some settings. For example, in the next line the zoom is adjusted to 100%.

objectClip Dup Call(CX_Open) Call(PrintPreview)
objectClip
Call(GetApplication) Call(GetActiveWindow) Call(GetActivePane) Call(GetView) Call(GetZoom) 100 Swap Call(PutPercentage)

Easy printing
For simple printing we can use the Word Print dialog box. The user can then, as with "normal" Word printing, make further settings (pages from-to, number of copies, etc.) before triggering printing. Since Word tries to open itself this way, we make it invisible again in the next line.

88 objectClip Dup Call(Activate) Call(GetApplication) Call(GetDialogs) Call(Item) Call(Show)
0 objectClip Call(GetApplication) Call(PutVisible)

Create a PDF/print multiple copies
However, if we want to save/archive the Word document as PDF, we have to go through a different print call to pass various information to Word. In the first lines we exchange the printer if FinePrint is the default printer, otherwise the printing is done via an intermediate window and the ps file is not completed in time (before the batch file is started). The next step is to start printing (Call(PrintOut)). This call requires all kinds of transfer parameters, which are described in the table 'Parameter list'. Creating the PDF file from the ps file is still done via the batch file.

objectClip Call(GetApplication) Call(GetActivePrinter) "FinePrint" StringFind if
{
   "Generic PostScript Printer" objectClip Call(GetApplication) Call(PutActivePrinter)
}

DropAll
t  f  f  postscriptFileName  "1" "100" f  t  "" f  t  objectClip  Call(PrintOut)

Parameter list

Stack - Top PrintToFile Controls printing to a file
Stack - Top-1 PageType
Pages "1;3;5-7"
Copies Number of copies "2"
Item
To Home page number "1"
From End page number "100"
OutputFileName If the PrintToFile flag is set to 'TRUE', you can specify the file name here "C:\fileName.ps"
Range
Background
Stack - Top-n Append

When printing any number of copies, the same method is used and the 'Copies' flag is set. There are two things to keep in mind. Firstly, the number is passed as a string and secondly, the flags 'PrintToFile' and 'OutputFileName' should not be set, otherwise the printout will be sent to a file.